这个题怎么做呀?"输入一个整数n,打印n行的杨辉三角(n为输入,并且小于15).

来源:百度知道 编辑:UC知道 时间:2024/05/17 01:33:46
如下图:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
请大家用C程序做一下,方法越多越好,谢谢!

不知道是要用什么语语做出来?别的我不会,我只能给你C++的
include "iostream"
include "math"
using namespace std;
int main()
{
const int x;
int y;
cout<<"输入要打印的几行为N:";
cin>>y;
x=y;
int a[x]={1,1};
for(int i=0;i<x;i++)
{
for(int j=0;j<=i;j++)
{
if(j==i)
{
cout<<a[j]<<endl;
}
else if(j==0)
{
cout<<a[j];
}
else
{
cout<<a[j-1]+a[j];
}
}
}
}

#include "stdio.h"
#define size 16
void main()
{
int n=0,i=0,j=0;
int sanjiao[size]={1},linshi[size]={1};

printf("请输入杨辉三角的行数n<16\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
i